package com.china08.yxyapi.api.home.weikecheng;

import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.china08.yxyapi.api.YxyApiBaseController;
import com.china08.yxyapi.entity.db.res.YxyKnowledge;
import com.china08.yxyapi.model.YxyApiRespModel;
import com.china08.yxyapi.repository.db.YxyKnowledgeRepository;

/**
 * 微课首页初始化---初始化默认 :小学+数学+区域微课+最新上传倒序
 * 
 */
@CrossOrigin
@RestController
public class WeikeHomeNoAuthController extends YxyApiBaseController {

    @Autowired
    private YxyKnowledgeRepository yn;

    @ResponseBody
    @RequestMapping(value = "/api_yw/home/weike/non/init", method = RequestMethod.GET)
    public RespModel process(HttpServletRequest request, HttpServletResponse response) {

        RespModel model = new RespModel();

        List<KnowRespModel> knowledges = new ArrayList<KnowRespModel>();
        List<YxyKnowledge> knowledgelList = yn.findByStageAndSubjectAndDeleteFlag(model.stage, model.subject, "1");

        for (YxyKnowledge yxyKnowledge : knowledgelList) {
            KnowRespModel knowRespModel = new KnowRespModel();
            knowRespModel.id = yxyKnowledge.getId();
            knowRespModel.pId = yxyKnowledge.getParentId();
            knowRespModel.name = yxyKnowledge.getName();
            knowledges.add(knowRespModel);
        }
        model.knowledges = knowledges;
        model.setMessage("成功");
        return model;
    }

    // 数学 12 ==》》》jcsub02
    protected static class RespModel extends YxyApiRespModel {

        public String stage = "01";// 小学

        public String subject = "jcsub02";// 数学

        public String stageName = "小学"; // 学段名称

        public String subjectName = "数学";// 学科名称

        public List<KnowRespModel> knowledges;// 知识点树
    }

    protected static class KnowRespModel extends YxyApiRespModel {

        public Integer id;// 知识点id

        public Integer pId;// 知识点父id

        public String name;// 知识点名称
    }

}
